<h1>Listing exams</h1>
<script type="text/javascript">
	var exam_id = null;
	function change_owner(id)
	{
		new Effect.Appear('user_list')
		exam_id = id
	}
	
	function close_change_owner()
	{
		new Effect.Fade('user_list')
	}
	
	function submit_change()
	{
		if(exam_id == null) return;
		index = $('user_last_name').selectedIndex;
		uid = $('user_last_name').options[index].value;
		window.location = '/exam/change/' + exam_id + '?user_id=' + uid;
	}
</script>

<table>
  <tr>
    <th>Title</th>
    <th>User</th>
  </tr>
  
<div id="user_list" style="display:none;">
	<%= collection_select(:user, :last_name, @users, :id, :last_name) %><br/>
	<a href="#" onClick="js:submit_change();">Change owner</a> - 
	<a href="#" onClick="js:close_change_owner();">Close</a> <br/>
</div>
<% for exam in @exams %>
  <tr>
    <td><%= h exam.title %></td>
    <td><%= h exam.user.last_name %></td>
    <td><%= link_to 'Show', :action => 'show', :id => exam %></td>
    <td><%= link_to 'Edit', :action => 'edit', :id => exam %></td>
    <td><%= link_to 'Copy', :action => 'copy', :id => exam %></td>
    <td>
    	<a href="#" onClick="js:change_owner(<%= exam.id %>);">Change owner</a>
    </td>
    <td><%= link_to 'Destroy', { :action => 'destroy', :id => exam }, :confirm => 'Are you sure?', :method => :post %></td>
  </tr>
<% end %>
</table>

<%= link_to 'Previous page', { :page => @exam_pages.current.previous } \
		if @exam_pages.current.previous %>
<%= link_to 'Next page', { :page => @exam_pages.current.next } \
		if @exam_pages.current.next %> 

<br />

<%= link_to 'New exam', :action => 'new' %>
